package com.platform.controller;

import com.platform.entity.OrderDrawbackEntity;
import com.platform.service.OrderDrawbackService;
import com.platform.service.OrderService;
import com.platform.utils.PageUtils;
import com.platform.utils.Query;
import com.platform.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 退款申请
Controller
 *
 * @author liweihai
 * @email liweihai12345@sina.com
 * @date 2019-04-24 18:03:19
 */
@RestController
@RequestMapping("orderdrawback")
public class OrderDrawbackController {
    @Autowired
    private OrderDrawbackService orderDrawbackService;


    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("orderdrawback:list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<OrderDrawbackEntity> tOrderDrawbackList = orderDrawbackService.queryList(query);
        int total = orderDrawbackService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(tOrderDrawbackList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{orderNo}")
    @RequiresPermissions("orderdrawback:info")
    public R info(@PathVariable("orderNo") String orderNo) {
        OrderDrawbackEntity tOrderDrawback = orderDrawbackService.queryObject(orderNo);

        return R.ok().put("tOrderDrawback", tOrderDrawback);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("orderdrawback:save")
    public R save(@RequestBody OrderDrawbackEntity tOrderDrawback) {
        orderDrawbackService.save(tOrderDrawback);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("orderdrawback:update")
    public R update(@RequestBody OrderDrawbackEntity tOrderDrawback) {
        orderDrawbackService.update(tOrderDrawback);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("orderdrawback:delete")
    public R delete(@RequestBody String[] orderNos) {
        orderDrawbackService.deleteBatch(orderNos);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<OrderDrawbackEntity> list = orderDrawbackService.queryList(params);

        return R.ok().put("list", list);
    }
}
